Multithreading is a common programming techniques often used to maximize the efficiency of computer programs by providing a tool to permit concurrency or multitasking. Threads are ways for a computer program to be divided into multiple and distinct sequences of programming instructions where each sequence is treated as a single task. By assigning different tasks to multiple threads, programmers can design a program in a way that multiple tasks are executed concurrently.
One of the essential functions of a thread is to manage resources used by a task. A particular portion of resource such as a system memory, e.g. random access memory (RAM), may be shared between multiple threads or used only by a single thread. Generally, allocation of resources by a requesting thread is required. Managing the particular portion of resource allocated by the requesting thread is referred to as the per-thread context management. For example, allocating and releasing the resources specifically used by a thread.
Another programming technique often used to enhance software development is to maximize program reuse and to minimize program rewrite. Conventionally, a program designed to be executed on specific operating systems, e.g. Windows™ 98, IA-32, etc., must be rewritten or at least encapsulated if the program is to be executed on a different platform. Programming language such as Java™ has attempted to introduce and deliver a write once and deploy anywhere mechanism. For example, the Java™ virtual machine is a platform that creates a virtual environment and enables programming code such as Java™ to be executed independent of the underlying hardware, e.g. Itanium™, SPARC™, PA-RISC, etc. Programming code that may be executed independent of the underlying hardware may be referred to as the platform-independent code.
A conventional method to permit the execution of platform-independent code on any hardware platform may require a translator. The translator translates the platform-independent code to a native code understood by the specific platform. For example, in a managed runtime environment that supports platform-independent managed code such as Java bye code, a Java™ virtual machine may be used to translate the Java byte code to platform specific code. In this case, the Java™ virtual machine is a binary translator that translates the Java byte code to platform specific code.
Managing multiple threads in a platform-independent code can be challenging. Traditionally, each thread is created and managed by underlying supporting libraries. For example, a thread written in C programming language is created and managed by the standard C library or the standard thread library. The underlying supporting library allocates resources such as stack frame saved register status, control words, and per-thread local resource.
Conventionally, a thread is created by the following procedure. First, a parent thread calls a routine, e.g. CreateThread( ), to create a child thread. CreateThread( ) can be an application programming interface (API) defined in a thread library. When the thread library receives this function call, the thread library allocates resources, such as the ones described above, for the new child thread. Subsequent to the allocation of child thread resources, the thread library sends a request to an operating system and requests a creation of the new child thread. This may be necessary because while the thread library may manage per-thread context, the operating system may manage the multiple threads operations. For example, the operating system manages the intercommunication between multiple threads.
After the operating system has successfully created the new child thread, the thread library will complete the new thread initialization by associating the resources of a parent thread with the newly created child thread. The parent thread is referred to as the portion of the programming code that initiates the child thread creation. While the child thread may freely use the allocated resources, the parent thread needs to maintain an access to the child thread. This may be done by providing or retaining an access to the child thread from the parent thread and associating the resource allocated for the child thread with the parent thread.
After the child thread has completed its task, the thread is usually terminated and the resources are returned to a resource pool so other threads may use the resource. An API call to the thread library, e.g. TerminateThread( ) could initiate the termination process. When TerminateThread( ) is called, the thread library would de-allocate the resources that were allocated during the thread initialization process. Subsequent to the de-allocation of thread resource, the thread library sends a notification to the operation system and notifies an exit or termination of the child thread.
When executing threads on a different platform, the platform may be equipped with different underlying supporting libraries and may not support the native thread code. As a result, a child native thread may not have been created and initialized properly. For example, a thread that has not been initialized due to lack of proper underlying supporting libraries may not be able to access its local variable because data structures and memory of this local variable have not yet been properly allocated.
Another challenge in program reuse may occur when porting existing program from a slower processor environment (e.g. a 32-bit program) to a faster processor environment (e.g. a 64-bit platform). In this situation, the 32-bit program is conventionally executed on an instruction set architecture (ISA) that supports 32-bit program, e.g. ISA-32. On the other hand, the faster processor environment may support only ISA-64 specific programming code. When attempting to execute the 32-bit program on a 64-bit platform, a mix ISA Execution (MIE) has occurred.
Contents of the Invention
A multithreaded program including a mixture of thread codes such as the platform-independent thread code (e.g. Java™ byte code) and native thread code (e.g. C), may be ported and transferred to a new platform that may not support the native thread code. Conventionally, when a multithreaded program including a mixture of code is ported to a new platform, a dynamic binary translator may be used to translate the entire program including the platform-independent code such that the ported program may be executed on the new platform. However, translating the entire program may cause the program to be inefficient. Instead, the problem is how to manage and support per-thread context wherein the native thread code may be transparently initiated and created in the new platform.
One embodiment of the invention includes a method to initialize a native thread code from a new platform and suspend the initialization of the native code at a position where it can later be associated with a new thread created in the new platform.
One embodiment of the invention includes a method to create a new thread from a new platform and associate the resource allocated for a native thread with the new thread created in the new platform.
An advantage of the embodied solutions is that a multithreaded program including a mixture of platform independent code and native thread code may be executed on a new platform without rewriting the program.